/**
 * offsetof.c 
 * test offsetof function. get the offset of a field in a struct.
 * @author: zt 2013-8-6
 */
#include<stdio.h>
#include<stddef.h>

struct node
{
    int size;
    char* nameStr; 
    int age;
};

#define zt_offsetof(type, member) ((size_t)&((type*)0)->member)

int main(void)
{
    printf("offset of nameStr: %4d\n", offsetof(struct node, nameStr));
    printf("offset of age: %4d\n", zt_offsetof(struct node, age));
    getchar();
    return 0; 
}
